﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using SqlOperate;
using System.Data.SqlClient;

public partial class Purchase_VisitorAdd : BasePage
{
    private static string _KeyTitle = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["txtKeyTitle"]!=""&&Request.Form["txtKeyTitle"]!=null)
        {
            _KeyTitle=Request.Form["txtKeyTitle"].ToString();
        }
        if (!IsPostBack)
        {
            this.bt.Text = Common.GetBottom(bt.Text);
            this.dl.Text = Base.Common.GetBottom(this.dl.Text);
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string code = this.yanzheng.Text;
        //验证码
        if (!CheckCode(code))   //验证码检测
        {
            ShowMessage("验证码错误！");
            return;
        }
        string UserIP = Request.UserHostAddress;
        string TelePhone = txtTel_International.Text.Trim() + txtTel_DistrictNumber.Text.Trim() + txtTel_Telephone.Text.Trim() + txtTel_Ext.Text.Trim();
        SqlConnection con = new SqlConnection(SqlHelper.ConnectionString);
        SqlCommand cmd = new SqlCommand("Pu_AddPurchase", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@LinkName",txtLinkName.Text.Trim());
        cmd.Parameters.AddWithValue("@CompanyName",txtCompanyName.Text.Trim());
        cmd.Parameters.AddWithValue("@Email",txtEmail.Text.Trim());
        cmd.Parameters.AddWithValue("@TelePhone",TelePhone);
        cmd.Parameters.AddWithValue("@Mobile",txtMobilePhone.Text.Trim());
        cmd.Parameters.AddWithValue("@UserIP",UserIP);
        SqlParameter ID = new SqlParameter("@ID",SqlDbType.Int);
        ID.Direction = ParameterDirection.Output;
        cmd.Parameters.Add(ID);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Redirect("PurchaseAdd.aspx?VisitorID=" + ID.SqlValue.ToString()+"&Title="+_KeyTitle);
    }
}
